package com.matou.commons.handler;


import com.matou.commons.constants.Resp;
import com.matou.commons.exception.MtError;
import com.matou.commons.util.BaseUtil;
import org.springframework.http.MediaType;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author CM
 * @Date 2021/5/9 9:44
 * @Description CmAccessDeniedHandler 处理资源服务器异常 主要处理 用户无权限  403
 * @Version 1.0
 */
public class MaTouAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        // 没有权限访问该资源
        BaseUtil.makeResponse(
                httpServletResponse, MediaType.APPLICATION_JSON_UTF8_VALUE,
                HttpServletResponse.SC_FORBIDDEN, Resp.failure(MtError.MT_001003));
    }
}
